<?php
header('Content-Type:text/html;charset=utf-8');
require('../../public/zscg.php');
require('../../public/local.php');
$uname=$_POST['uname'];
$nicheng=$_POST['nicheng'];
// $e_mail=$_POST['e_mail'];
$pwd1=$_POST['pwd1'];
$pwd=$_POST['pwd'];
@$res1=select2($con,'user','where `username` = "'.$uname.'"')[0];
$pattern='/\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/';
if(empty($res1)){
    echo "<script>alert('不存在的用户名');window.location.href='/home/change_pwd/index3.php'</script>";
    die;
}elseif($nicheng!=$res1['nicheng']){
    echo "<script>alert('昵称输入错误');window.location.href='/home/change_pwd/index.php'</script>";
    die;
}elseif($pwd1 != $pwd){
    echo "<script>alert('两次输入的密码不相同');window.location.href='/home/change_pwd/index.php'</script>";
    die;
}elseif(strcasecmp($_POST['yzm']==$_COOKIE['yzm'])){
    echo "<script>alert('请输入正确的验证码');window.location.href='/home/change_pwd/index.php'</script>";
    die;
}
$arr=array('password'=>$pwd);
$res2=update($con,'user',$res1['id'],$arr);
if($res2){
    echo "<script>alert('密码已重置');window.location.href='/index.php'</script>";
}else{
    echo "<script>alert('密码重置失败');window.location.href='/home/change_pwd/index.php'</script>";
}